package Day2025_04_15;

import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) arr[i] = in.nextLong();
        long[] dp = new long[n + 1];
        long ret = -0x3f3f3f3f;
        for (int i = 1; i <= n; i++) {
            dp[i] = Math.max(dp[i - 1] + arr[i - 1], arr[i - 1]);
            ret = Math.max(ret, dp[i]);
        }
        System.out.println(ret);
    }
}
